home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / docdemos / stringdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  1.2 KB  |  53 lines

  1. program StringDemo (Output);
  2.  
  3. type
  4.   SType = String (10);
  5.   SPtr  = ^String;
  6.  
  7. var
  8.   Str  : SType;
  9.   Str2 : String (100000);
  10.   Str3 : String (20) value 'string expression';
  11.   DStr : ^String;
  12.   ZStr : SPtr;
  13.   Len  : Integer value 256;
  14.   Ch   : Char value 'R';
  15.  
  16. { `String' accepts any length of strings }
  17. procedure foo (z : String);
  18. begin
  19.   WriteLn ('Capacity : ', z.Capacity);
  20.   WriteLn ('Length   : ', Length (z));
  21.   WriteLn ('Contents : ', z);
  22. end;
  23.  
  24. { Another way to use dynamic strings }
  25. procedure Bar (SLen : Integer);
  26. var
  27.   LString : String (SLen);
  28.   FooStr  : type of LString;
  29. begin
  30.   LString := 'Hello world!';
  31.   Foo (LString);
  32.   FooStr := 'How are you?';
  33.   Foo (FooStr);
  34. end;
  35.  
  36. begin
  37.   Str  := 'KUKKUU';
  38.   Str2 := 'A longer string variable';
  39.   New (DStr, 1000);  { Select the string Capacity with `New' }
  40.   DStr^ := 'The maximum length of this is 1000 chars';
  41.   New (ZStr, Len);
  42.   ZStr^ := 'This should fit here';
  43.   Foo (Str);
  44.   Foo (Str2);
  45.   Foo ('This is a constant string');
  46.   Foo ('This is a ' + Str3);
  47.   Foo (Ch);  { A char parameter to string routine }
  48.   Foo ('');  { An empty string }
  49.   Foo (DStr^);
  50.   Foo (ZStr^);
  51.   Bar (10000);
  52. end.
  53.